﻿Module initialize_application
    Public Sub initialize_app()
        Dim start_up_par() As String = Environment.GetCommandLineArgs().ToArray
        Dim st_par_count As Integer = start_up_par.Length - 1

        If (My.Settings.en_ocr_gen) Then
            Form1.gb_ocr_gen.Visible = True
        Else
            Form1.gb_ocr_gen.Visible = False
        End If

        If Not Form1.debug Then
            check_temp_dir(My.Settings.source_dir)
            check_temp_dir(My.Settings.tmp_dir)
            check_temp_dir(My.Settings.dest_dir)
        End If

        If (st_par_count > 0) Then
            Form1.gb_manu.Visible = False
        Else
            Form1.gb_manu.Visible = True
            Form1.num_wafers = 0
        End If
    End Sub

    Public Sub check_temp_dir(ByRef mypath As String)
        If Not IO.Directory.Exists(mypath) Then
            ' Nein! Jetzt erstellen...
            Try
                IO.Directory.CreateDirectory(mypath)
                ' Ordner wurde korrekt erstellt!
            Catch ex As Exception
                MsgBox("Could not create directory: " & mypath & ". Maybe no write permission")
                Form1.Close()
            End Try
        Else
            Try
                Dim s As String
                For Each s In System.IO.Directory.GetFiles(mypath)
                    System.IO.File.Delete(s)
                Next
            Catch ex As Exception
                MsgBox("Could not clean up directory: " & mypath & ". Maybe no write permission")
                Form1.Close()
            End Try
        End If
    End Sub
End Module
